package {
import flash.display.Sprite;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;

public class TestRemote extends Sprite {
        private var blazeUrl:String = "http://localhost:8080/messagebroker/";
	    private var remoteService:RemoteObject = new RemoteObject();
    
        public function TestRemote() {
            var cs:ChannelSet = new ChannelSet();
		    var myAMF:Channel = new AMFChannel("my-amf", blazeUrl + "amf"); 
		    cs.addChannel(myAMF);
		    remoteService.channelSet = cs;

            remoteService.showBusyCursor = true;
            remoteService.destination = "crawlerService";

            remoteService.addEventListener(FaultEvent.FAULT, defaultFaultHandler);
            remoteService.getMsg.addEventListener(FaultEvent.FAULT, defaultFaultHandler);
            remoteService.getMsg.addEventListener(ResultEvent.RESULT, defaultResultHandler);

            remoteService.getMsg();
        }

        private function defaultResultHandler(event:ResultEvent):void {
            trace(event);
            Alert.show(event.message.body.toString());
        }

        private function defaultFaultHandler(fault:FaultEvent):void {
            trace(fault);
            Alert.show(fault.toString());
        }
    }
}